package com.xpgk.mvc.bsendMessage;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 计算培训总价格
 * @author Administrator
 *
 */
public class CountTrainTotalPrice {

	/**
	 * 
	 * @param startTime 开始时间  10:00
	 * @param endTime 结束时间    11:45
	 * @param unitprice  单价（每小时的价格）
	 * @return   返回      本次培训产生多少钱    如：115元  ，和  本次培训花费了多少分钟 如：30分钟  ，60分钟 
	 */
	public static Map<String, Object> ClearingTrainPrice(Date startTime,Date endTime,float unitprice,int timeLength)throws Exception{
		int startTimeSecond = DateUtil.getSeconds("HH:mm", DateUtil.dateFormat("HH:mm", startTime));
		int endTimeSecond = DateUtil.getSeconds("HH:mm", DateUtil.dateFormat("HH:mm", endTime));
		int minute = (endTimeSecond - startTimeSecond) / 60 ;//练车分钟
		int  Number = minute / 30;
		if(Number > 0){
			int remainder = minute % 30;
			if(remainder < timeLength){
				minute = Number * 30;
			}else{
				minute = (Number + 1) * 30;
			}
		}else{
			int remainder = minute % 30;
			if(remainder < timeLength){
				minute = 0;
			}else{
				minute = 30;
			}
		}
		float totalPrice = minute * (unitprice / 60) ;
		Map<String,Object> maplist = new HashMap<String, Object>();
		maplist.put("totalPrice", totalPrice);
		maplist.put("minutes", minute);
		return maplist;
		
	}
	public static void main(String[] args) {
		Date startTime = DateUtil.convertToDate("10:00","HH:mm");
		Date endTime = DateUtil.convertToDate("10:14","HH:mm");
		
		Map<String, Object> dd = null;
		try {
			dd = ClearingTrainPrice(startTime,endTime,50,15);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(dd.get("totalPrice")+"-----"+dd.get("minutes"));
	}
}
